package com.cryptooj.project.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 *  用户角色
 * */
public enum UserRoleEnum {

    USER("用户","user"),
    ADMIN("管理员","admin"),
    BAN("封禁用户","ban");

    private final String text;

    private final String value;

    UserRoleEnum(String text,String value){
        this.text = text;
        this.value = value;
    }

    public static List<String> getValues(){
        return Arrays.stream(values())
                .map(item ->item.value)
                .collect(Collectors.toList());
    }

    public static UserRoleEnum getEnumByValue(String value){
        if(ObjectUtils.isEmpty(value)){
            return null;
        }
        for(UserRoleEnum ure : UserRoleEnum.values()){
            if(ure.value.equals(value)){
                return ure;
            }
        }
        return null;
    }

    public String getText() {
        return text;
    }

    public String getValue() {
        return value;
    }
}
